﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompleteReader.Dialogs
{
    /// <summary>
    /// This class works as a base class for the various dialogs used in this app.
    /// This lets the main window tell the dialog to close. A dialog deriving from this class can override the CloseDialog function,
    /// play an animation, and then call base.CloseDialog() when finished. This allows the dialog to animate out to a side of the window.
    /// </summary>
    public class CloseableDialog : Windows.UI.Xaml.Controls.UserControl
    {
        public delegate void OnDialogClosed();

        public event OnDialogClosed DialogClosed;

        protected bool _Closing = false;
        protected bool _Closed = true;
        protected bool _Opening = false;
        protected bool _Opened = false;


        /// <summary>
        /// Override this to provide an animation when closing the dialog. Make sure to call this function when finished with animation.
        /// </summary>
        public virtual void CloseDialog()
        {
            _Closing = false;
            _Closed = true;
            _Opening = false;
            _Opened = false;
            this.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            if (DialogClosed != null)
            {
                DialogClosed();
            }
        }

        /// <summary>
        /// OVerride this to provide an animation when opening the dialog.
        /// </summary>
        public virtual void OpenDialog()
        {
            _Closing = false;
            _Closed = false;
            _Opening = false;
            _Opened = true;
            this.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
    }
}
